import { fileURLToPath, URL } from "node:url";

import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";

// https://vitejs.dev/config/
/** @type {import('vite').UserConfig} */
export default ({ command, mode }: any) => {
  console.log(command, "command");
  console.log(mode, "mode");
  console.log(loadEnv(mode, process.cwd()));
  return defineConfig({
    plugins: [vue(), vueJsx()],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    // vite 配置
    // 根据当前工作目录中的 `mode` 加载 .env 文件
    define: {
      __APP_URL__: loadEnv(mode, process.cwd()).APP_URL,
    },
  });
};
